public class ControlPanel {

    private enum State {
        IDLE, READING_CHAR, VERIFYING_PASSWORD, LOCKED
    }

    private State currentState = State.IDLE;

    private String inputPassword = "";
    private int errorCount = 0;
    private long lockTime = 0;
    private String correctPassword = "1234"; // 设置的正确密码

    public void handleKeyInput(char key) {
        switch (currentState) {
            case IDLE:
                if (key == '敲击键盘') { // 敲击键盘进入读取字符状态
                    currentState = State.READING_CHAR;
                }
                break;
            case READING_CHAR:
                inputPassword += key; // 记录输入字符
                if (inputPassword.length() == 4) { // 输入字符数达到4位，进入验证密码状态
                    currentState = State.VERIFYING_PASSWORD;
                } else if (errorCount >= 3) { // 输入错误次数达到3次，进入锁定状态
                    currentState = State.LOCKED;
                    lockTime = System.currentTimeMillis(); // 记录锁定时间
                }
                break;
            case VERIFYING_PASSWORD:
                if (inputPassword.equals(correctPassword)) { // 密码正确，进入系统功能选择状态
                    currentState = State.IDLE; // 这里可以改为进入系统功能选择状态
                    inputPassword = ""; // 清空输入密码
                    errorCount = 0; // 重置错误次数
                } else { // 密码错误，返回读取字符状态
                    currentState = State.READING_CHAR;
                    errorCount++; // 错误次数加1
                    inputPassword = ""; // 清空输入密码
                }
                break;
            case LOCKED:
                if (System.currentTimeMillis() - lockTime > 120000) { // 锁定时间超过120秒，返回待机状态
                    currentState = State.IDLE;
                    errorCount = 0; // 重置错误次数
                }
                break;
        }
    }

    // 其他方法，例如获取当前状态、显示提示信息等
}
